package peration;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class DelBook implements IOperation{
    @Override
    public void dowork(BookList bookList) {
        int size = bookList.getUsedSize();
        System.out.println("请输入你要删除的书名");
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();
        int pos = -1;
        for(int i=0; i<size; i++){
            Book book = bookList.getBook(i);
            if( book.getName().equals(name) ){
                pos = i;
            }
        }
        if(pos > -1){
            for( int i=pos ; i<size-1; i++){
                Book book = bookList.getBook(i+1);
                bookList.putBook(i, book);
            }
            bookList.setUsedSize(bookList.getUsedSize()-1);
            System.out.println("删除成功");
        }
        else{
            System.out.println("没有" + name + "这本书");
            return;
        }

    }
}
